from rest_framework.routers import DefaultRouter
from .views import SellerViewSet, BuyerViewSet, CategoryViewSet
from django.urls import path, include

# 卖家路由 - 使用viewset自动生成标准CRUD接口
seller_router = DefaultRouter()
seller_router.register('seller', SellerViewSet, basename='seller-products')

# 买家路由 - 只读接口，单独定义
buyer_router = DefaultRouter()
buyer_router.register('buyer', BuyerViewSet, basename='buyer-products')

# 分类路由 - 只读接口
category_router = DefaultRouter()
category_router.register('categories', CategoryViewSet, basename='category')

urlpatterns = [
    # 包含自动生成的标准路由
    path('', include(seller_router.urls)),
    path('', include(buyer_router.urls)), 
    path('', include(category_router.urls)),
        path('buyer/<str:product_code>/', BuyerViewSet.as_view({'get': 'retrieve'})),

    # 分类相关自定义接口
    path('categories/<int:pk>/products/', 
         CategoryViewSet.as_view({'get': 'products'}), 
         name='category-products'),
]